<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改员工信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
</head>
<body>
<div style="height:700px;width:80%;margin:15px auto;overflow:auto;" id="aaa">
    <form class="layui-form" action="">
        <input type="hidden" class="input-text" id="id" name="id">
        <div class="layui-form-item">
            <label class="layui-form-label">员工姓名<span style="color:red">*</span></label>
            <div class="layui-input-block">
                <input type="text" name="name" id="name" required  lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">员工编号<span style="color:red">*</span></label>
            <div class="layui-input-block">
                <input type="text" name="bh" id="bh" required  lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">状态<span style="color:red">*</span></label>
            <div class="layui-input-block">
                <select lay-verify="required" lay-search id="status" name="status">
                    <option value="1">启用</option>
                    <option value="0">禁用</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">所属商户<span style="color:red">*</span></label>
            <div class="layui-input-block">
                <select lay-verify="required" lay-search id="cla">
                    <!--<option id="eee" disabled selected></option>-->
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">联系方式</label>
            <div class="layui-input-block">
                <input type="text" name="phone" id="phone" required  lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">员工地址</label>
            <div class="layui-input-block">
                <input type="text" name="address" id="address" required  lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item" style="margin-top: 20px">
            <div class="layui-input-block">
                <button class="layui-btn" id="updateBusinessStaff" lay-submit lay-filter="updateBusinessStaff">立即修改</button>
                <button type="reset" id="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script src="/js/layui/layui.js"></script>
<script src="/js/layui/layui.all.js"></script>
<script src="/admin/js/token.js"></script>

<script>

    //url 传参
    function GetQueryString(name){
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var a = decodeURI(window.location.search);
        var r = a.substr(1).match(reg);//search,查询？后面的参数，并匹配正则
        if(r!=null)return  unescape(r[2]); return null;
    }

    window.onload = function(){
        var form = layui.form;
        $("input[name='id']").val(GetQueryString("id"));
        $("input[name='name']").val(GetQueryString("name"));
        $("input[name='bh']").val(GetQueryString("bh"));
        $("input[name='phone']").val(GetQueryString("phone"));
        $("input[name='address']").val(decodeURIComponent(GetQueryString("address")));
        $('#status').find("option[value="+GetQueryString("status")+"]").attr("selected",true);
        form.render('select');
    }

    layui.use(['form' , 'jquery'], function(){
        var form = layui.form;
        var $ = layui.jquery;

        //修改操作
        form.on('submit(updateBusinessStaff)',function(data){
            var busiBh = $("#cla").find("option:selected").val();
            data.field.busiBh = busiBh;
            data.field.id = $("#id").val();
            if(busiBh==null || busiBh==""){
                layer.msg('请选择商户');
                return false;
            }
            $.ajax({
                url: "/businessStaff/updateBusinessStaff"
                ,type:"POST"
                ,contentType: 'application/json'
                ,data:JSON.stringify(data.field)
                , success: function (data) {
                    if(data.code==500) {
                        layer.msg(data.data);
                    }else if(data.code==200){
                        layer.close(layer.index);
                        layer.msg('修改成功');
                        setTimeout(function(){
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);//关闭弹出层
                            parent.location.reload();//重新加载父页面表格
                        }, 2000);
                    }
                }
                , error: function () {
                    console.log("ajax error");
                }
            });
            return false;
        });

        $.ajax({
            url: "/business/selectBusinessStatus"
            , type: "POST"
            , contentType: 'application/json'
            , data: {'status': 1}
            , success: function (data) {
                //$('#cla').append(new Option(GetQueryString("businessName"),GetQueryString("businessBh"),true));
                $.each(data.data, function (index, item) {
                    $('#cla').append(new Option(item.name, item.bh));// 下拉菜单里添加元素
                });
                $('#cla').val(GetQueryString("businessBh"));
                //$('#cla').find("option[value="+GetQueryString("businessBh")+"]").attr("selected",true);
                layui.form.render("select");
            }
        });
    });
</script>
</body>
</html>